package com.migu.contacts.main;

import static com.migu.contacts.net.Service.API;

import android.util.Log;
import android.view.View;

import com.frank.libandroid.BaseFragment;
import com.frank.libandroid.DataStore;
import com.frank.libandroid.HttpCallback;
import com.frank.libandroid.butterknife.OnClick;
import com.migu.contacts.R;
import com.migu.contacts.bean.UserBean;
import com.migu.contacts.databinding.FragmentMyBinding;
import com.migu.contacts.main.my.AdviceActivity;
import com.migu.contacts.main.my.InstructionActivity;
import com.migu.contacts.main.my.ScoreActivity;
import com.migu.contacts.main.my.SettingActivity;
import com.migu.contacts.main.my.UserLabelActivity;
import com.migu.contacts.main.my.VIPActivity;
import com.migu.contacts.util.UserCenter;

public class MyFragment extends BaseFragment<FragmentMyBinding> {
    @OnClick(R.id.loginBtn)
    public void login() {
        API.getUserInfo().watch(this, new HttpCallback<UserBean>() {
            @Override
            protected void onSuccess(UserBean messageBean) {
                Log.d(TAG, "onSuccess() called with: messageBean = [" + messageBean + "]");
                DataStore.put(UserEditActivity.CONTACT_BEAN_KEY, messageBean);
                start(UserEditActivity.class);
                UserCenter.userBean = messageBean;
            }
        });

    }

    @OnClick(R.id.renmai)
    public void renmai() {
        start(RenMaiActivity.class);
    }

    @OnClick(R.id.vip)
    public void vip() {
        start(VIPActivity.class);
    }

    @OnClick(R.id.score)
    public void score() {
        start(ScoreActivity.class);
    }

    @OnClick(R.id.instruction)
    public void instruction() {
        start(InstructionActivity.class);
    }

    @OnClick(R.id.advice)
    public void advice() {
        start(AdviceActivity.class);
    }

    @OnClick(R.id.setting)
    public void setting() {
        start(SettingActivity.class);
    }

    @OnClick(R.id.group)
    public void group() {
        start(GroupEditActivity.class);
    }

    @OnClick(R.id.label)
    public void label() {
        start(UserLabelActivity.class);
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    @Override
    protected void initData() {
        super.initData();
        API.getUserInfo().watch(this, new HttpCallback<UserBean>() {
            @Override
            protected void onSuccess(UserBean messageBean) {
                Log.d(TAG, "onSuccess() called with: messageBean = [" + messageBean + "]");
                mBinding.setBean(messageBean);
                UserCenter.userBean = messageBean;
                if (UserCenter.isVip()) {
                    mBinding.vipTitle.setVisibility(View.GONE);
                } else {
                    mBinding.vipTitle.setVisibility(View.VISIBLE);
                }
            }
        });
    }
}
